﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;

namespace ASP.ADO
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ManagerAgency.mdf;Integrated Security=True;User Instance=True");
            SqlCommand command = new SqlCommand();
            command.CommandText = "SELECT * FROM HoSoDaiLy";
            command.CommandType = CommandType.Text;
            command.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            da.Fill(ds, "BookIssueDetails");
            if (ds.Tables[0].Rows.Count > 0)
            {
                grdXML.DataSource = ds;
                grdXML.DataBind();
            }

            // Get a FileStream object
            StreamWriter xmlDoc = new StreamWriter(Server.MapPath("~/FileTest/Testdo.xml"), false);
            // Apply the WriteXml method to write an XML document
            ds.WriteXml(xmlDoc);
            xmlDoc.Close();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            StreamReader xmlReader=new StreamReader(Server.MapPath("~/FileTest/Testdo.xml"),false);
            ds.ReadXml(xmlReader);

            SqlConnection con = new SqlConnection(@"Data Source=TANNGUYEN-LAP\SQLEXPRESS;Initial Catalog=MANAGERAGENCY.MDF;Integrated Security=True");

            

            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand("usp_InsertHoSoDaiLy", con);

            foreach(DataTable temp in ds.Tables)
            {

            }




        }
    }
}